package com.example.redis;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@SpringBootApplication
@RestController
@RequestMapping
public class RedisApplication {

    @Autowired
    private Redisson redisson;

    public static void main(String[] args) {
        SpringApplication.run (RedisApplication.class, args);
    }

    @GetMapping("/get")
    public String get(){
        RLock lock = redisson.getLock ("1");
        lock.lock ();
        try {
            Thread.sleep (120000);
            System.out.println ("111");
        }catch (Exception e){
            e.printStackTrace ();
        }finally {
            lock.unlock ();
        }
        return "ok";
    }


}
